package com.cc.data_explore.gui.base;

import atlantafx.base.theme.PrimerLight;
import com.cc.data_explore.gui.helper.StageHelper;
import javafx.application.Application;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Modality;
import javafx.stage.Stage;

import java.io.IOException;

/**
 * @author cc
 * @version 1.0
 * @since 2025/4/3
 */
public class BaseView {

    public void showDialog(String title, Parent parent, boolean resizable) {
        try {
            // 加载 FXML 文件
            createScene(title, parent, resizable);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void showDialog(String title, Parent parent) {
        try { // 加载 FXML 文件
            createScene(title, parent, true);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private void createScene(String title, Parent parent, boolean resizable) throws IOException {
        Scene scene = new Scene(parent, 1024, 768);
        Stage stage = new Stage();
        stage.setTitle(title);
        stage.initModality(Modality.WINDOW_MODAL);
        scene.getStylesheets().add(getClass().getResource("/style.css").toExternalForm());
        stage.setScene(scene);
        stage.setResizable(resizable);
        stage.initOwner(StageHelper.getStage("mainStage"));
        StageHelper.addStage(title, stage);
        stage.setOnCloseRequest(event -> {
            StageHelper.removeStage(title);
        });
        stage.show();
    }

}
